﻿package dk.gaming.rummikub.primitive
{
	import flash.display.MovieClip;
	import fl.motion.Color;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class Tile extends MovieClip
	{
		
		private var number : Number;
		private var color : Color;
		private var joker : Boolean;
		private var replacement : Boolean;
		
		private var NumberText : TextField;
		private var Symbol : MovieClip;
		private var JokerSymbol : MovieClip;
		private var ReplacementSymbol : MovieClip;
		
		public function Tile($number:Number, $color:Color, $joker:Boolean=false, $replacement:Boolean=false)
		{
			if($joker)
			{
				this.Joker($joker);
			}
			else if($replacement)
			{
				this.Replacement($replacement);
			}
			else
			{
				this.Number($number);
				this.Color($color);
			}
			
		}
		
		public function set Number($number:Number):void
		{
			number = $number;
			NumberText.text = $number.toString();
		}
		
		public function get Number():Number
		{
			return number;
		}
		
		public function set Color($color:Color):void
		{
			var tf : TextFormat = new TextFormat();
			tf.color = $color.color;
			this.color = $color;
			NumberText.setTextFormat(tf);
		}
		
		public function get Color():Color
		{
			return color;
		}
		
		public function set Joker($joker:Boolean):void
		{
			this.joker = $joker;
			if(this.joker)
			{
				NumberText.visible = false;
				JokerSymbol.visible = true;
				ReplacementSymbol.visible = false;
			}
		}
		
		public function get Joker():Boolean
		{
			return this.joker;
		}
		
		public function set Replacement($replacement:Boolean):void
		{
			this.replacement = $replacement;
			if(replacement)
			{
				NumberText.visible = false;
				JokerSymbol.visible = true;
				ReplacementSymbol.visible = false;
			}
		}
		
		public function get Replacement():Boolean
		{
			return replacement;
		}
		
		public function Activate():void
		{
			this.addEventListener(MouseEvent.MOUSE_DOWN, BeginDrag);
		}
		
		private function BeginDrag(e:MouseEvent):void
		{
			
		}
		
		private function EndDrag(e:MouseEvent):void
		{
			
		}
		
		
	}
	
	
}